/**
 *
 */
package com.jcode.netty.process;

import com.jcode.netty.core.RequestProcessor;
import com.jcode.netty.protocol.Packet;
import com.jcode.netty.protocol.PacketUtil;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @Desc
 * @Author dreajay
 * @DateTime 2016年8月31日 下午2:37:30
 */
public class DefaultRequestProcessor implements RequestProcessor {

    private final static Logger log = LoggerFactory.getLogger(DefaultRequestProcessor.class);

    private final static AtomicLong count = new AtomicLong(0);


    public DefaultRequestProcessor() {
    }

    @Override
    public Packet processRequest(ChannelHandlerContext ctx, Packet request) throws Exception {
        log.info(count.incrementAndGet() + "---"  + request);
        if (request.isOnewayType()) {
            return null;
        }
        if (request.isResponseType()) {
            return null;
        }
        Packet response = PacketUtil.createResponsePacket(request, 2, null);
        return response;
    }

}
